<template>
    <div class="table-container">
      <div class="table-container__top">
        <div class="table-container__top--title">待办项目列表</div>
      </div>
    <div class="table-border" v-if="tableData?.list?.length>0">
      <common-table2 :data="tableData"  :fromMenu = "1" @refresh-list="refresh"></common-table2>
    </div>
    <div v-else class="table-container__empty">
        <img class="table-container__empty--img" src="@/assets/icons/svg/empty.svg" alt="">
        <div class="table-container__empty--text">暂无内容</div>
      </div>
    </div>
</template>
<script lang="jsx" setup>
import { useRouter } from 'vue-router';
import CommonTable2 from '@/views/components/table/CommonTable2.vue';
import { getApprovalList } from '@/api/sjhg/approval';

const router = useRouter();
const goRoute = (path, id) =>{
          const query = {}
            if (id) {
              query.id = id
            }
            router.push({
              path: './' + path,
              query,
            })
}
//-------------------------接口------------------------------------
const tableData = ref({});
let params = {
  pageNum :1,
  pageSize : 10,
  status: 1,
  sortField: 'update_time',
  sortOrder: 'DESC',
}
const refresh = (changeParams) =>{
  if(changeParams?.pagination){
    params.pageNum = changeParams.pagination.current
    params.pageSize = changeParams.pagination.pageSize
  }else if(changeParams?.sorter){
    params.pageNum = 1
    params.sortOrder = changeParams?.sorter.descending ? 'DESC':'ASC'
    if(changeParams?.sorter.sortBy === 'approvalTime'){
      params.sortField = 'approval_time'
    }else if(changeParams?.sorter.sortBy === 'submitTime'){
      params.sortField = 'submit_time'
    }else if(changeParams?.sorter.sortBy === 'approval_process'){
      params.sortField = 'approval_process'
    }
  }else{
    params.pageNum = 1
    params.sortField = 'update_time'
    params.sortOrder = 'DESC'
  }
  getList();
}
// 审核侧评估项目列表
onMounted(async() => {
  await getList();
})
const getList = () => {
    getApprovalList(params)
      .then((res) => {
        if (res.code == 200) {
          tableData.value = res.data || {}
          const list = []
          res.data?.list?.forEach(element => {
            // list.push(...element?.child)
            list.push(element)
          });
          tableData.value.list = list
          console.log('tableData = ', tableData.value)
        } else {
        }
      }).finally(() => {
      });
  }
</script>
<style lang="scss" scoped>
</style>
